package com.atguigu.gmall.search.rpc;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.search.entity.Goods;
import com.atguigu.gmall.search.service.SearchService;
import com.atguigu.gmall.search.vo.SearchParamVo;
import com.atguigu.gmall.search.vo.SearchRespVo;
import org.simpleframework.xml.Path;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author tangsy
 * @Description TODO
 * @date 2022/12/12 18:53
 * @Version 1.0
 */
@RequestMapping("api/inner/rpc/search")
@RestController
public class SearchRpcController {

    @Autowired
    SearchService searchService;

    /**
     * 上架
     * @param goods
     * @return
     */
    @PostMapping("/up/goods")
    public Result up(@RequestBody Goods goods){
        searchService.up(goods);
        return Result.ok();
    }

    /**
     * 下架
     * @param skuId
     * @return
     */
    @GetMapping ("/down/goods/{skuId}")
    public Result down(@PathVariable("skuId")Long skuId){
        searchService.down(skuId);
        return Result.ok();
    }

    @PostMapping("/searchgoods")
    public Result<SearchRespVo> search(@RequestBody SearchParamVo vo){
        SearchRespVo resp = searchService.search(vo);
        return Result.ok(resp);
    }

    @GetMapping("/hotscore/{skuId}/{score}")
    public Result updateHotScore(@PathVariable("skuId") Long skuId,
                                 @PathVariable("score") Long score){

        searchService.updateHotScore(skuId,score);
        return Result.ok();
    }

}
